package com.nuumoblie.bluetoothtools

import android.Manifest
import android.content.Intent
import android.view.View
import com.nuumoblie.bluetoothtools.ble.BlePeripheralListActivity
import com.nuumoblie.bluetoothtools.bt.BtClientActivity
import com.nuumoblie.bluetoothtools.bt.BtServerActivity
import com.nuumoblie.bluetoothtools.bt.sdp.SDPClientActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity(), View.OnClickListener {

    override fun getContentLayoutId(): Int {
        return R.layout.activity_main;
    }


    override fun initView(): Unit {

    }

    override fun initData() {

    }

    override fun initEvent(): Unit {
        btn_bt_server.setOnClickListener(this);
        btn_bt_client.setOnClickListener(this);
        btn_peripheral.setOnClickListener(this)
        btn_sdp.setOnClickListener(this)
        checkAndEnableBt();
        rxPermissions.request(
            Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.BLUETOOTH_ADVERTISE,Manifest.permission.BLUETOOTH_CONNECT
        )
            .subscribe();
    }

    override fun onClick(v: View?) {

        when (v?.id) {
            R.id.btn_bt_server -> {
                startActivity(Intent(this, BtServerActivity::class.java));
            };
            R.id.btn_bt_client -> {
                startActivity(Intent(this, BtClientActivity::class.java));
            };
            R.id.btn_peripheral -> {
                startActivity(Intent(this, BlePeripheralListActivity::class.java));
            };
            R.id.btn_sdp -> {
                startActivity(Intent(this, SDPClientActivity::class.java));
            };
            else -> {

            }
        }

    }

}
